package map.makeLand;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    static int[][] dir = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    static int count;
    public static void dfs(int[][] grid, boolean[][] visited, int x, int y, int mark){
        if (visited[x][y] || grid[x][y] == 0){
            return;
        }
        visited[x][y] = true;
        grid[x][y] = mark;
        count++;
        for (int i = 0; i < 4; i++) {
            int nextX = x + dir[i][0];
            int nextY = y + dir[i][1];
            if (nextX < 0 || nextY < 0 || nextX >= grid.length || nextY >= grid[0].length){
                continue;
            }
            dfs(grid, visited, nextX, nextY, mark);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int rows = sc.nextInt();
        int cols = sc.nextInt();
        int[][] grid = new int[rows][cols];
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                grid[i][j] = sc.nextInt();
            }
        }
        boolean[][] visited = new boolean[rows][cols];
        int mark = 2;
        boolean isAllLand = true;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (grid[i][j] == 0){
                    isAllLand = false;
                }
                if (!visited[i][j] && grid[i][j] == 1){
                    count = 0;
                    dfs(grid, visited, i, j, mark);
                    map.put(mark, count);
                    mark++;
                }
            }
        }
        int result = 0;
        if (isAllLand){
            result = rows * cols;
        }
        HashSet<Integer> visitedGrid = new HashSet<>();
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (grid[i][j] == 0){
                    count = 1;
                    visitedGrid.clear();
                    for (int k = 0; k < 4; k++) {
                        int nextX = i + dir[k][0];
                        int nextY = j + dir[k][1];
                        if (nextX < 0 || nextY < 0 || nextX >= grid.length || nextY >= grid[0].length){
                            continue;
                        }
                        int curMark = grid[nextX][nextY];
                        if (visitedGrid.contains(curMark) || !map.containsKey(curMark)){
                            continue;
                        }
                        visitedGrid.add(curMark);
                        count += map.get(curMark);
                    }
                    result = Math.max(result, count);
                }
            }
        }
        System.out.println(result);
    }
}
